package com.atguigu.realtime.demos

import java.time.{Instant, LocalDateTime, ZoneId}
import java.time.format.DateTimeFormatter

/**
 * Created by Smexy on 2022/8/26
 */
object TSParseDemo {

  def main(args: Array[String]): Unit = {

    /*
        在java8之后，要使用java.time包下的类处理时间
             DateTimeFormatter: 时间格式
             LocalDateTime:      代表一个时间
     */

    val ts = 1661324237000l;

    val formatter1: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
    val formatter2: DateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")

    val time: LocalDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(ts), ZoneId.of("Asia/Shanghai"))

    val dateTimeStr: String = time.format(formatter1)
    val dateStr: String = time.format(formatter2)

    println(dateTimeStr)
    println(dateStr)




  }

}
